package io;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

import io.User.Gender;

public class UserExternal implements Externalizable {
	
	
	public UserExternal() {
		
	}
	public UserExternal(String name, int age,int deposit,Gender gender) {
		super();
		Name = name;
		Age = age;
		Deposit = deposit;
		this.gender = gender;
	}
//实现序列化和反序列话自定义

		public String getName() {
			return Name;
		}
		public void setName(String name) {
			Name = name;
		}
		public int getAge() {
			return Age;
		}
		public void setAge(int age) {
			Age = age;
		}
		public String Name;
		public int Age;
		public int Deposit;
		public  Gender gender;
		public Gender getGender() {
			return gender;
		}
		public void setGender(Gender gender) {
			this.gender = gender;
		}
		public static enum Gender{
			GAY,Male,FEMALE
		}
		public int getDeposit() {
			return Deposit;
		}

		public void setDeposit(int deposit) {
			Deposit = deposit;
		}

		@Override
		public void writeExternal(ObjectOutput out) throws IOException {
			out.writeInt(getDeposit());
			out.writeInt(getAge());
			out.writeInt(getGender() == gender.Male ? 1:0);
		}

		@Override
		public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
			Deposit = in.readInt();
			Age = in.readInt();
			setGender(in.readInt() == 1 ? Gender.Male:Gender.FEMALE);
		}
}
